﻿

class HistoryDrawGrid extends BaseDrawGrid {

    lightColor: number = 255;

    Draw(drawArea: IDrawArea) {
        var output = "";
        output = "";
        for (var x = 0; x < this.grid.Width; x++) {
            for (var y = 0; y < this.grid.Height; y++) {
                if (this.grid.GetCell(x, y).State == CellState.Alive)
                    drawArea.GetRenderingContext().fillStyle = "#505080";
                else {
                    if (this.grid.GetCell(x, y).IterationsSinceLastCellChange < 5)
                        drawArea.GetRenderingContext().fillStyle = "#FFFFFF";
                    else {

                        var rgb = Math.floor(255 - ((this.grid.GetCell(x, y).IterationsSinceLastCellChange - 5) / 10));
                        if (rgb < 120) rgb = 120;
                        drawArea.GetRenderingContext().fillStyle = "rgb(" + rgb + "," + rgb + "," + Math.floor(rgb * 1.5) + ")";

                    }
                }
                drawArea.GetRenderingContext().fillRect(x * this.rectWidthInt, y * this.rectHeightInt, this.rectWidthInt, this.rectHeightInt);
            }

        }

        //var output = "";
        //output += this.grid.NrOfIteration;
        //output += " / "
        //output += this.grid.GetNrOfCellsOfState(CellState.Alive);
        //output += " / "
        //output += this.grid.GetNrOfCellsOfState(CellState.Dead);

        ////var content = document.getElementById('status');
        ////content.innerHTML = output;




    }
}

class TextDrawGridText implements IDrawGrid {
    grid: IGrid;

    Init(grid: IGrid) {
        this.grid = grid;
    }

    Draw() {
        var output = "";
        output = "";
        for (var x = 0; x < this.grid.Width; x++) {
            output += "<br>";
            for (var y = 0; y < this.grid.Height; y++) {
                if (this.grid.GetCell(x, y).State == CellState.Alive)
                    output += "o";
                else
                    output += "_";
            }

        }

        var content = document.getElementById('content');
        content.innerHTML = output;

    }
} 